package com.cskaoyan.service;

import com.cskaoyan.bean.*;
import com.cskaoyan.bean.vo.GoodsVo;
import com.cskaoyan.mapper.MarketGoodsAttributeMapper;
import com.cskaoyan.mapper.MarketGoodsMapper;
import com.cskaoyan.mapper.MarketGoodsProductMapper;
import com.cskaoyan.mapper.MarketGoodsSpecificationMapper;
import com.cskaoyan.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

public class GroupGoodsDetailServiceImpl implements GroupGoodsDetailService {
    @Override
    public GoodsVo selectGoods03(String goodsId) {
        int goodId = Integer.parseInt(goodsId);
        SqlSession session = MyBatisUtil.getSqlSession();

        MarketGoodsMapper marketGoodsMapper = session.getMapper(MarketGoodsMapper.class);
        MarketGoodsAttributeMapper marketGoodsAttributeMapper = session.getMapper(MarketGoodsAttributeMapper.class);
        MarketGoodsSpecificationMapper marketGoodsSpecificationMapper = session.getMapper(MarketGoodsSpecificationMapper.class);
        MarketGoodsProductMapper marketGoodsProductMapper = session.getMapper(MarketGoodsProductMapper.class);

        MarketGoods marketGoods = marketGoodsMapper.selectByPrimaryKey(goodId);

        MarketGoodsAttributeExample example01 = new MarketGoodsAttributeExample();
        MarketGoodsSpecificationExample example02 = new MarketGoodsSpecificationExample();
        MarketGoodsProductExample example03 = new MarketGoodsProductExample();
        example01.createCriteria().andGoodsIdEqualTo(goodId);

        int a = marketGoodsAttributeMapper.selectByExample(example01).size();
        MarketGoodsAttribute[] marketGoodsAttributes = marketGoodsAttributeMapper.selectByExample(example01).toArray(new MarketGoodsAttribute[a]);
        example02.createCriteria().andGoodsIdEqualTo(goodId);
        int b = marketGoodsSpecificationMapper.selectByExample(example02).size();
        MarketGoodsSpecification[] marketGoodsSpecifications = marketGoodsSpecificationMapper.selectByExample(example02).toArray(new MarketGoodsSpecification[b]);
        example03.createCriteria().andGoodsIdEqualTo(goodId);
        int c = marketGoodsProductMapper.selectByExample(example03).size();
        MarketGoodsProduct[] marketGoodsProducts = marketGoodsProductMapper.selectByExample(example03).toArray(new MarketGoodsProduct[c]);

        GoodsVo goodsVo01 = new GoodsVo();
        goodsVo01.setGoods(marketGoods);
        goodsVo01.setProducts(marketGoodsProducts);
        goodsVo01.setAttributes(marketGoodsAttributes);
        goodsVo01.setSpecifications(marketGoodsSpecifications);

        return goodsVo01;
    }

}

